<?php
namespace Home\Controller;
use Think\Controller;
class UserInfoController extends Controller {
    public function index(){
        $uid=session('uid');
       $userinfo=M("users")->where(array("uid" => $uid))->select();
        $upic=M('users')->where(array("uid"=>$uid))->select();
        $this->userinfo=$userinfo;
        if(!$uid)
        {$this->error('登录已过期!',U("Home/Login/index"));}
        elseif($userinfo){
            $this->assign('list', $userinfo);
            $this->assign('upic', $upic);
            $this->display();
        }
        else{ $this->error('获取失败!', U("Home/UserInfo/index"));}
    }
    public function reset(){
        $data['username'] = trim(I('post.username'));
        $data['birthday'] = trim(I('post.birthday'));
        $data['qq'] = trim(I('post.qq'));
        $data['tel'] = trim(I('post.tel'));
        $data['intro'] = trim(I('post.intro'));

        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 3145728 ;// 设置附件上传大小
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath = './Public/images/pic/'; // 设置附件上传根目录
        $upload->autoSub = false;
        $info = $upload->uploadOne($_FILES['pic']);
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }
        $data['pic']=$info['savepath'].$info['savename'];
        $id['uid']=trim(I('post.uid'));
        $a=M("users");
       /* $result=$a->where(array('username'=>$data['username']))->find();*/
        if($a){ $a->where($id)->save($data);
            
            $this->success('修改成功',U("Home/UserInfo/index"));}
        else{
            $this->error('修改失败！', U("UserInfo/index"));
        }
    }
}